package com.ymatou.iapi.dguser.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.shenqisettlement.parameter.resp.GetUserBandingBankCardInfoResp;
import com.ymatou.iapi.dguser.parameter.UnwxbindBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.UnwxbindCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;

import sun.util.logging.resources.logging;
/**
*解绑微信Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Unwxbind{
	private static UnwxbindBean unwxbindBean;
	private static UnwxbindCall unwxbindCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解绑微信Test");
	}

	@Before
	public void caseUp() {
		unwxbindBean=new UnwxbindBean();
		unwxbindCall=new UnwxbindCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unwxbindCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Unwxbind_001() {
		Logger.start(true,"正确数据，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			unwxbindBean.setUserId(user);
			unwxbindCall.setData(unwxbindBean);
			unwxbindCall.callService();			
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
			dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(0, dgUserBindInfo.size(), "微信已经解绑");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Unwxbind_002() {
		Logger.start(true,"再次解绑");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			unwxbindBean.setUserId(user);
			unwxbindCall.setData(unwxbindBean);
			unwxbindCall.callService();			
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
			dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(0, dgUserBindInfo.size(), "微信已经解绑");
			unwxbindCall.callService();
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Unwxbind_003() {
		Logger.start(true,"userid错误");
		try {
			unwxbindBean.setUserId(13123);
			unwxbindCall.setData(unwxbindBean);
			unwxbindCall.callService();			
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_Unwxbind_004() {
		Logger.start(true,"微信解绑，验证微信token是否失效");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			Map<String, Object> wxLogin = DGUserCallService.WxLogin(u, user);
			System.out.println("token:"+wxLogin.toString());
			unwxbindBean.setUserId(user);
			unwxbindCall.setData(unwxbindBean);
			unwxbindCall.callService();			
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
			DGUserCallService.WxLogin(u, user);
			AuthCallServiceV2.signAuth(wxLogin.get("sId").toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Unwxbind_005() {
		Logger.start(true,"微信解绑，删除unionid--手动看数据库");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			Thread.sleep(20000);
			unwxbindBean.setUserId(user);
			unwxbindCall.setData(unwxbindBean);
			unwxbindCall.callService();			
			Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
			dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(0, dgUserBindInfo.size(), "微信已经解绑");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}